Blockchain for Enterprise by Narayan Prusty

Blockchain for Enterprise by Narayan Prusty

Author:Narayan Prusty
Language: eng
Format: epub
Tags: COM018000 - COMPUTERS / Data Processing, COM083000 - COMPUTERS / Security / Cryptography, COM062000 - COMPUTERS / Data Modeling and Design
Publisher: Packt Publishing
Published: 2018-09-26T10:26:24+00:00


Sending ether

Let's look at how to send ether to any address. To send ether, you need to use the web3.eth.sendTransaction() method. This method can be used to send any kind of transaction but is mostly used to send ether. This is because deploying a contract or calling a method of contract using this method is cumbersome as it requires you to manually generate the data of the transaction rather than automatically generating it. It takes a transaction object that has the following properties:

from: The address for the sending account. This uses the web3.eth.defaultAccount property if not specified.

to: This is optional. It's the destination address of the message and is left undefined for a contract-creation transaction.

value: This is optional. The value of the transaction is transferred in wei as well as the endowment if it's a contract-creation transaction.

gas: This is optional. It's the amount of gas to use for the transaction (unused gas is refunded). If this is not provided, then it's automatically determined.

gasPrice: This is optional. It's the price of gas for this transaction in wei, and it defaults to the mean network gas price.

data: This is optional. It's either a byte string containing the associated data of the message or, in the case of a contract-creation transaction, the initialization code.

nonce: This is optional. It's an integer. Every transaction has nonce associated with it. nonce is a counter that indicates the number of transactions made by the sender. If it is not provided, it will be automatically determined. It helps prevent replay attacks. This nonce is not the nonce associated with a block. If we are using a nonce greater than the nonce that the transaction should have, then the transaction is put in a queue until the other transactions arrive. For example, if nonce of the next transaction should be four and we set the nonce to ten, then geth will wait for the remaining six transactions before broadcasting this transaction. The transaction with nonce ten is called a queued transaction, and is not a pending transaction.



Download



Copyright Disclaimer:
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.